<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="记录id（uuid）">
          <a-input placeholder="请输入记录id（uuid）" v-decorator="['logId', validatorRules.logId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家id - 预留字段（uuid）">
          <a-input placeholder="请输入专家id - 预留字段（uuid）" v-decorator="['expertId', validatorRules.expertId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家编号 - 唯一标识">
          <a-input placeholder="请输入专家编号 - 唯一标识" v-decorator="['experNum', validatorRules.experNum ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="专家姓名">
          <a-input placeholder="请输入专家姓名" v-decorator="['experName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者姓名">
          <a-input placeholder="请输入患者姓名" v-decorator="['patientName', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者性别（字典数据，1：男；2：女）">
          <a-input placeholder="请输入患者性别（字典数据，1：男；2：女）" v-decorator="['patientSex', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者年龄">
          <a-input placeholder="请输入患者年龄" v-decorator="['patientAge', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者身份证号">
          <a-input placeholder="请输入患者身份证号" v-decorator="['patientSfzh', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者住院号">
          <a-input placeholder="请输入患者住院号" v-decorator="['patientNum', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者住院科室">
          <a-input placeholder="请输入患者住院科室" v-decorator="['patientDep', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者电话">
          <a-input placeholder="请输入患者电话" v-decorator="['patientPhone', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者诊断">
          <a-input placeholder="请输入患者诊断" v-decorator="['patientDiagnosis', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="患者手术名称">
          <a-input placeholder="请输入患者手术名称" v-decorator="['nameOfOperation', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="诊断时间">
          <a-input placeholder="请输入诊断时间" v-decorator="['diagnosisTime', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "InviteExpertModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        logId:{rules: [{ required: true, message: '请输入记录id（uuid）!' }]},
        expertId:{rules: [{ required: true, message: '请输入专家id - 预留字段（uuid）!' }]},
        experNum:{rules: [{ required: true, message: '请输入专家编号 - 唯一标识!' }]},
        },
        url: {
          add: "/hospital/inviteExpert/add",
          edit: "/hospital/inviteExpert/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'logId','expertId','experNum','experName','patientName','patientSex','patientAge','patientSfzh','patientNum','patientDep','patientPhone','patientDiagnosis','nameOfOperation'))
		  //时间格式化
          this.form.setFieldsValue({diagnosisTime:this.model.diagnosisTime?moment(this.model.diagnosisTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>